package cn.kn.triage.sys.controller;

import cn.kn.triage.common.model.PageBean;
import cn.kn.triage.common.model.R;
import cn.kn.triage.sys.model.Role;
import cn.kn.triage.sys.service.RoleService;
import cn.kn.triage.sys.vo.IRoleVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

/**
 * @author yinzn
 * @create 2020-10-16 14:33
 */
@RequestMapping("sys/role")
@RestController
@CrossOrigin/*跨域请求*/
public class RoleController {
    private final RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping
    public R add(@RequestBody Role role){
        return roleService.add(role);
    }

    @DeleteMapping("/{roleId}")
    public R del(@PathVariable Long roleId){
        return roleService.del(roleId);
    }

    @RequiresPermissions("sys:user:get")
    @GetMapping
    public R get(){
        return roleService.get();
    }

    @GetMapping("list")
    public R list(PageBean pageBean,String roleName){
        return roleService.list(pageBean,roleName);
    }

    @PutMapping("/{roleId}")
    public R update(@PathVariable Long roleId, @RequestBody IRoleVo iRoleVo){
        return roleService.update(roleId,iRoleVo);
    }

    @GetMapping("all")
    public R all(){
        return roleService.all();
    }




}
